using System;
using System.Collections.Generic;
using System.Text;

namespace XDL.Framework.Collections
{
    class NamedServiceContainer
    {

        /// <summary>
        /// Underlying storage map
        /// </summary>
        Dictionary<string, object> m_services = new Dictionary<string, object>();
    
        /// <summary>
        /// Add a service
        /// </summary>
        /// <param name="name">Service name</param>
        /// <param name="provider">Service provider instance</param>
        public void AddService(string name, object provider)
        {
            m_services.Add(name, provider);
        }

        /// <summary>
        /// Returns a service from its name.
        /// </summary>
        /// <typeparam name="T">Service type.</typeparam>
        /// <param name="name">Service name</param>
        /// <returns>An instance of the requested service</returns>
        public T GetService<T>(string name) where T : class
        {
            return (T)m_services[name];
        }
    }
}
